#include<iostream>
using std::cout;
#include"stonewt.h"

Stonewt::Stonewt(double lbs)
{
	stone = int(lbs) / Lbs_per_stn;
	pds_left = int(lbs) % Lbs_per_stn + lbs - int(lbs);
	pounds = lbs;
	mode = LBS;
}

Stonewt::Stonewt(int stn, double lbs)
{
	stone = stn;
	pds_left = lbs;
	pounds = stn * Lbs_per_stn + lbs;
	mode = STN;
}

Stonewt::Stonewt()
{
	stone = pounds = pds_left = 0;
}

Stonewt::~Stonewt()
{

}

void Stonewt::show_stn()
{
	//cout << stone << " stone, " << pds_left << " pounds\n";
	mode = STN;
}

void Stonewt::show_lbs()
{
	//cout << pounds << " pounds\n";
	mode = LBS;
}

Stonewt Stonewt::operator+(const Stonewt& b) const
{
	Stonewt sum;
	sum.stone = stone + b.stone;
	sum.pds_left = pds_left + b.pds_left;
	sum.pounds = pounds + b.pounds;
	return sum;
}

Stonewt Stonewt::operator-(const Stonewt& b) const
{
	Stonewt sum;
	sum.stone = stone - b.stone;
	sum.pds_left = pds_left - b.pds_left;
	sum.pounds = pounds - b.pounds;
	return sum;
}

Stonewt Stonewt::operator*(double m) const
{
	Stonewt sum;
	sum.stone = stone * m;
	sum.pds_left = pds_left * m;
	sum.pounds = pounds * m;
	return sum;
}

std::ostream& operator<<(std::ostream& os, const Stonewt& s)
{
	if (s.mode == Stonewt::LBS)
	{
		os << s.pounds << " pounds\n";
	}
	else if (s.mode == Stonewt::STN)
	{
		os << s.stone << " stone, " << s.pds_left << " pounds\n";
	}
	else
	{
		os << "Stonewt object mode is invalid";
	}
	return os;
}
